//
//  CoreUserEmailTextFieldComponent.m
//  CoreUser
//
//  Created by Demi on 20/04/2017.
//  Copyright © 2017 Azazie. All rights reserved.
//

#import "CoreUserEmailTextFieldComponent.h"

#import <base/base.h>

@implementation CoreUserEmailTextFieldComponent

- (void)prepare
{
    [super prepare];
    self.placeholderLabel.text = @"Email";
    self.textField.keyboardType = UIKeyboardTypeEmailAddress;
    self.textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
}

- (BOOL)validate
{
    BOOL isValid = [self.textField.text isValidEmail];
    if (!isValid)
    {
        self.invalid = YES;
    }
    return isValid;
}

- (void)setInvalid:(BOOL)invalid
{
    if (invalid)
    {
        if (self.textField.text.length > 0)
        {
            self.errorLabel.text = @"Please check your email format.";
        }
        else
        {
            self.errorLabel.text = @"Please enter an email address.";
        }
    }
    [super setInvalid:invalid];
}

@end
